package com.koron.order.common.controller;

import com.koron.bean.base.Response;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.order.common.bean.dto.OrderDispatchDto;
import com.koron.order.common.bean.vo.OrderDispatchVo;
import com.koron.order.common.service.OrderDispatchInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;

@Api(tags = "工单派工")
@RequestMapping("/orderDispatch/")
@RestController
public class OrderDispatchController {

    @Autowired
    OrderDispatchInfoService orderDispatchInfoService;

    public String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "新增或更新")
    @PostMapping("saveDispatchInfo")
    public Response<String> saveDispatchInfo(@RequestBody OrderDispatchDto dto) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderDispatchInfoService, "insertOrUpdate", String.class, dto));
    }

    @ApiOperation(value = "根据orderId删除")
    @DeleteMapping("deleteDispatchInfo")
    public Response<Integer> deleteDispatchInfo(@NotBlank @RequestParam String orderId) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderDispatchInfoService, "deleteByOrderId", Integer.class, orderId));
    }

    @ApiOperation(value = "根据orderId查询 ")
    @GetMapping("queryDispatchInfoByOrderId")
    public Response<OrderDispatchVo> queryDispatchInfoByOrderId(@NotBlank @RequestParam String orderId) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), orderDispatchInfoService, "queryByOrderId", OrderDispatchVo.class, orderId));
    }

}
